/* 
使用mockjs定义mock接口的模块
*/
import Mock from 'mockjs'

import data from './data.json'  // 得到解析好的js对象

import shops from './shops.json'
// 定义mock接口: goods
Mock.mock('/api/goods', {code: 0, data: data.goods})

// 定义mock接口: ratings
Mock.mock('/api/ratings', {code: 0, data: data.ratings})

// 定义mock接口: info
Mock.mock('/api/info', {code: 0, data: data.info})

// 不用向外暴露任何东西

//根据id动态匹配路由
Mock.mock(/^\/api\/shop\/\d+$/,function (options) {
    //得到url里的id
        const id = options.url.substring(10)
    //根据id返回对应的商家
        const shop = shops.find((item)=>{
            return item.id==id
        })
        return Mock.mock({code:0,data:shop})
})